<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    /* // 1 2 4 3  => Promise实例中 then方法对应的回调函数 => 不会再主线程直接执行(也会放在任务队列中 =>也属于异步任务)

    console.log(1);

    var p = new Promise(function(resolve,reject){
        console.log(2);
        resolve(3);
    })

    console.log(p);
    p.then(function(num){
        console.log(num);
    })

    console.log(4);


    //1  2   4   3 */


    /* console.log(1);

    var p = new Promise(function(resolve,reject){
        console.log(2);
        resolve(3);
    })

    console.log(p);
    p.then(function(num){
        console.log(num);
    })

    setTimeout(function(){
        console.log(5);
    })

    console.log(4);

    //1   2   4   3   5 */


    /* console.log(1);
    setTimeout(() => {
        console.log(2);
        Promise.resolve().then(() => {
            console.log(3)
        });
    });

    new Promise((resolve, reject) => {
        console.log(4)
        resolve(5)
    }).then((data) => {
        console.log(data);
    })

    setTimeout(() => {
        console.log(6);
    })

    console.log(7);

    //1   4   7   5   2   3    6 */


    console.log(1);
    setTimeout(() => {  //callback1

        console.log(2);
        Promise.resolve().then(() => {  //callback7

            console.log(3)
        });
    });

    new Promise((resolve, reject) => {

        console.log(4)
        resolve(5)
    }).then((data) => {  // callback2

        console.log(data);

        Promise.resolve().then(() => {  // callback4

            console.log(6)
        }).then(() => {      // callback5

            console.log(7)

            setTimeout(() => {   // callback6

                console.log(8)
            }, 0);
        });
    })

    setTimeout(() => {  // callback3

        console.log(9);
    })

    console.log(10);

    //1   4   10  5   6   7   2 3  9 8  
</script>
</html>